package com.stone.business.jxfa.service;

/**
 * <pre>
 * ---计划---Service
 * </pre>
 */

import java.util.HashMap;
import java.util.List;

import com.stone.business.jxfa.pojo.TJxfa;
import com.stone.business.jxfa.pojo.TJxfaBz;
import com.stone.business.jxfa.pojo.TJxfaGznr;
import com.stone.business.plan.pojo.TPlan;

import frm.ssh.exception.AppException;
import frm.ssh.service.BaseService;


public class JxfaService extends BaseService{

	public String doSave(TJxfa entity, List<TJxfaBz> bzlist,List<TJxfaGznr> gznrlist) {

		if (entity.getId() == 0) {
			entity.setStatus("1");
			super.save(entity);
			
			for (TJxfaBz bz : bzlist) {
				
				if (!"".equals(bz.getFzrname())) {
					bz.setDelflag("0");
				}else{
					bz.setDelflag("1");
				}
				bz.setJxfaid(entity.getId());
				super.save(bz);
			}
			if(gznrlist!=null){
			for(TJxfaGznr gznr : gznrlist){
				gznr.setJxfaid(entity.getId());
				super.save(gznr);
			}}
		}else{
			super.update(entity);
			for(TJxfaBz bz : bzlist){
				if(!"".equals(bz.getFzrname())){
					bz.setDelflag("0");
				}else{
					bz.setDelflag("1");
				}
				bz.setJxfaid(entity.getId());
				super.update(bz);
			}
			if(gznrlist!=null){
			for(TJxfaGznr gznr : gznrlist){
				gznr.setJxfaid(entity.getId());
				super.update(gznr);
			}}
		}
		
		return "保存成功。";
	}
	
	/**
	 * ....提交计划....
	 */
	public String doSubmit(TPlan entity,String status) {
		
		entity.setStatus(status);
		super.update(entity);
		return "提交成功。";
	}
	
	
	/**
	 * 删除
	 */
	public void delete(Long id) throws AppException {
		// 删除节点菜单
		super.delete(id, "Plan");
		// 删除按钮
		super.deleteByDHql("parentID = ? and btnId is not null", new Object[]{id}, "Plan");
	}

	/**
	 * 执行Hql查询查询
	 * 
	 * @param hql  查询语句
	 * @return List 结果集
	 */
	public List findListByHql(String hql)  {
			return super.findListByHql(hql);
	}
	
	/**
	 * 根据ID查询记录
	 * 
	 * @param id ID
	 * @param objectFullName POJO名 包括包路径
	 * @return Object
	 */
	public Object findById(Long id, String objectFullName)  {
		return super.findById(id, objectFullName);
	}
	
	/**
	 * 保存pojo对象
	 * 
	 * @param transientInstance pojo对象
	 */
	public void save(Object transientInstance)  {
			super.save(transientInstance);
	}
	
	/**
	 * 修改记录
	 * 
	 * @param transientInstance pojo对象
	 */
	public void update(Object transientInstance)  {
			super.update(transientInstance);
	}
	
	/**
	 * 修改记录
	 * 
	 * @param transientInstance pojo对象
	 */
	public void doDelAll(final String ids,final String objectSimpleName)  {
			super.doDelAll(ids,objectSimpleName);
	}
	
	/**
	 * 通过SQL查询列表，返回每条是一个HashMap<String,Object>
	 * @param sql 查询SQL语句
	 * @return list 返回列表
	 */
	public List<HashMap<String,Object>> findListBySql(String sql){
	
		List<HashMap<String,Object>> list =  (List<HashMap<String,Object>>) super.findListBySql(sql);
		return list;
	}

	
	/**
	 * 此方法是用来动态获取列表，可以多表关联
	 * 
	 * @param cols 查询列名
	 * @param conditions 查询条件
	 * @param vals 查询条件对应值
	 * @return clause order by, group by,having等子句
	 * @param objectSimpleName 
	 */
	public List getListByDHql(final String cols, final String conditions,
			final Object[] vals, final String clause,
			final String objectSimpleName)  {
		
		return super.getListByDHql(cols, conditions, vals, clause, objectSimpleName);
	}
	
	/**
	 * 根据ID删除记录
	 * 
	 * @param id 删除记录的ID
	 * @param objectSimpleName
	 */
	public void delete(Long id, String objectSimpleName){
			super.delete(id, objectSimpleName);
	}
	/**
	 * 通过HQL修改记录
	 * 
	 * @param hql 修改的HQL语句
	 * @param values HQL语句对应值
	 */
	public void updateByHQL(String hql, Object[] values){
		super.updateByHQL(hql,values);
	}
}
